import settings from "../utils/settings";
import { location } from "../utils/getLocation";

export function autois(){
    
register("step",()=>{
    if(settings.autois && (settings.autoisname == "" || settings.autoisname == Player.getName())) Client.showTitle("","&cBZA AutoIS 已启用",0,40,0);
}).setDelay(1)
register("worldLoad" , () => {
    if(settings.autois && (settings.autoisname == "" || settings.autoisname == Player.getName())){
    setTimeout(()=>{
    if(location.inSkyblock) {
        switch (settings.autoisto) {
            case 0.0:
                if(location.island != "Private Island") ChatLib.command(`is`); 
                break;
            case 1.0:
                if(location.island != "Garden") ChatLib.command('warp garden');
                break;
        }
    }else if(Scoreboard.getLines()[Scoreboard.getLines().length-1] == undefined){
        ChatLib.command('lobby');
    }else{
        ChatLib.command(`play skyblock`); 
    }
    }, settings.autoisdelay * 1000)
    }
});

const lobbyConfirm = register("chat",()=>{
    ChatLib.command(`lobby`);
}).setChatCriteria("Are you sure? Type /lobby again if you really want to quit.").unregister();

register("chat" , () => {
    if(settings.autois && (settings.autoisname == "" || settings.autoisname == Player.getName())){
        switch (Scoreboard.getLines()[Scoreboard.getLines().length-1] == undefined || location.inSkyblock) {
            case true:
                lobbyConfirm.register();
                setTimeout(() => { lobbyConfirm.unregister(); }, 1000);
                ChatLib.command('lobby');
            default:
                setTimeout(() => {
                    ChatLib.command("play skyblock");
                }, 60 * 1000);
                break;
        }
        return;
    }
    setTimeout(() => {
        if(Scoreboard.getLines()[Scoreboard.getLines().length-1] == undefined || location.inSkyblock)
            switch (settings.autobacktoskyblock) {
                case 2.0:
                    setTimeout(() => {
                        ChatLib.command("play skyblock");
                    }, 5000);
                case 1.0:
                    lobbyConfirm.register();
                    setTimeout(() => { lobbyConfirm.unregister(); }, 1000);
                    ChatLib.command('lobby');
                    break;
                default:
                    break;
            }
    }, 200);
}).setChatCriteria(/(You were kicked while joining that server!|Oops! You are not on SkyBlock so we couldn't warp you!)/)

}